package crossbreed.views.Controls;

import java.awt.Dimension;
import java.awt.Graphics;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import javax.swing.JComponent;
import javax.swing.text.Document;
import javax.swing.text.JTextComponent;

public class LineNumberPanel extends JComponent implements PropertyChangeListener 
{
	private static final long serialVersionUID = 1L;
	private JTextComponent component;

	public LineNumberPanel(JTextComponent component)
	{
		super();
		setPreferredSize(new Dimension(30, 30));
		this.component = component;
		this.component.addPropertyChangeListener("document", this);
	}

	public void paint(Graphics g)
	{	
		int lineHeight = g.getFontMetrics().getHeight();
		
		for (int i=0; i<500; i++)
		{
			g.drawString(Integer.toString(i), 0, i * lineHeight);
		}
	}

	@Override
	public void propertyChange(PropertyChangeEvent evt)
	{
		if (evt.getNewValue() instanceof Document)
		{
			repaint();
		}
	}
}